package com.xkdx.caipiao.wiget;

import android.app.AlertDialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.TextView;

import com.xkdx.caipiao.R;
import com.xkdx.caipiao.listener.OnAlertDialogOkListener;

public class MyAlertDialog {

	private static Context context;
	private static OnAlertDialogOkListener listenr;
	private static TextView ok;
	private static TextView cancle;

	public static AlertDialog creatAlertDialog(final Context cx, String title,
			String content) {
		context = cx;

		final AlertDialog dlg = new AlertDialog.Builder(context).create();

		dlg.show();

		Window window = dlg.getWindow();

		window.setContentView(R.layout.alertdialog_caipiao);

		ok = (TextView) window.findViewById(R.id.ok);
		cancle = (TextView) window.findViewById(R.id.cancle);
		TextView tv_title = (TextView) window.findViewById(R.id.title);

		TextView tv_content = (TextView) window.findViewById(R.id.content);

		if (TextUtils.isEmpty(title)) {
			tv_title.setText("亲情提示:");
		} else {

			tv_title.setText(title);
		}

		if (TextUtils.isEmpty(content)) {
			tv_content.setText("数据处理中");
		} else {

			tv_content.setText(content);
		}

		ok.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				dlg.dismiss();
				listenr.handleOkClick();
			}
		});

		
		cancle.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				dlg.dismiss();
				listenr.handleDismissClick();
			}
		});
		return dlg;
	}

	public static void setOkMessage(String message) {
		ok.setText(message);
	}

	public static  void setDismissMessage(String message1) {
		cancle.setText(message1);
	}

	public static void setOnAlertDialogOklistener(OnAlertDialogOkListener l) {
		listenr = l;
	}

}
